package com.spzx.product.controller;

import com.spzx.common.core.domain.R;
import com.spzx.common.core.utils.bean.BeanUtils;
import com.spzx.common.core.web.controller.BaseController;
import com.spzx.common.security.annotation.InnerAuth;
import com.spzx.product.api.domain.ProductSkuVo;
import com.spzx.product.domain.ProductSku;
import com.spzx.product.service.IProductSkuService;
import com.spzx.product.api.domain.SkuPriceVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 商品sku 前端控制器
 * </p>
 *
 * @author atguigu
 * @since 2024-12-20
 */
@RestController
@RequestMapping("/productSku")
public class ProductSkuController extends BaseController {

   @Autowired
    private IProductSkuService productSkuService;

    @InnerAuth
    @Operation(summary = "获取商品SKU详情")
    @GetMapping("/getProductSku/{skuId}")
    public R<ProductSkuVo> getProductSkuVo(
            @Parameter(description = "商品skuId")
            @PathVariable("skuId") Long skuId) {
        ProductSku productSku = productSkuService.getById(skuId);
        ProductSkuVo productSkuVo = new ProductSkuVo();
        BeanUtils.copyProperties(productSku, productSkuVo);
        return R.ok(productSkuVo);
    }

    @Operation(summary = "获取商品sku最新价格信息")
    @InnerAuth
    @GetMapping(value = "/getSkuPrice/{skuId}")
    public R<SkuPriceVo> getSkuPrice(@PathVariable("skuId") Long skuId)
    {
        return R.ok(productSkuService.getSkuPrice(skuId));
    }

    @Operation(summary = "批量获取商品sku最新价格信息")
    @InnerAuth
    @PostMapping(value = "/getSkuPriceList")
    public R<List<SkuPriceVo>> getSkuPriceList(@RequestBody List<Long> skuIdList)
    {
        return R.ok(productSkuService.getSkuPriceList(skuIdList));
    }

}
